home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / cli / stealcd1.lha / StealCD.mod < prev   
Text File  |  1995-08-28  |  3KB  |  153 lines

  1. (*************************************************************************
  2.   :Program.       StealCD
  3.   :Version.       V1.0 (28.08.95)
  4.   :Contents.      see --background--
  5.  
  6.   :Author.        Jan Hense [juh]
  7.   :Address.       Milchstr. 4, 81667 München, Germany
  8.   :Address.       Tel. +49-89-481960, e-mail j.hense@amc.cube.net
  9.   :Copyright.
  10.  
  11.   :Language.      Oberon (with Amiga Oberon extensions)
  12.   :Translator.    Amiga Oberon v3.00d
  13. **************************************************************************)
  14.  
  15. MODULE StealCD;
  16.  
  17. IMPORT
  18.  
  19.   Dos, Exec, SYSTEM;
  20.  
  21.  
  22. (*
  23. ******* StealCD/--background-- *******************************************
  24. *
  25. *   NAME
  26. *
  27. *       StealCD
  28. *
  29. *   SYNOPSIS
  30. *
  31. *       StealCD PROCESS/N/A
  32. *
  33. *   DESCRIPTION
  34. *
  35. *       Peeks the name of the current directory of another process and
  36. *       echos it to the standard output. To actually use it I recommend an
  37. *       alias of the form
  38. *
  39. *         ALIAS scd "CD *`StealCD []*`"
  40. *
  41. *       in your s:shell-startup.
  42. *
  43. *   OPTIONS
  44. *
  45. *       PROCESS - the number of another process as returned by the status
  46. *         cli command or the shell variable $process.
  47. *
  48. *   AUTHOR
  49. *
  50. *       Jan Hense
  51. *       Milchstr. 4
  52. *       81667 München, Germany
  53. *       Tel. +49-89-481960
  54. *       e-mail j.hense@amc.cube.net
  55. *
  56. *   COPYRIGHT
  57. *
  58. *       Freely distributable
  59. *
  60. **************************************************************************
  61. *
  62. *)
  63.  
  64. (*
  65. ******* StealCD/--history-- **********************************************
  66. *
  67. *   v1.0 (28.08.95) [juh]
  68. *
  69. *       Created initial version.
  70. *
  71. **************************************************************************
  72. *
  73. *   TO DO
  74. *
  75. *)
  76.  
  77.  
  78.  
  79. CONST
  80.  
  81.   template = "PROCESS/N/A"
  82.     "\o$VER: StealCD 1.0 (28.08.95) ©1995 j.hense@amc.cube.net";
  83.  
  84.   noSuchProcess = "No such process!\n";
  85.  
  86. TYPE
  87.  
  88.   ArgsStruct = STRUCT (as: Dos.ArgsStruct)
  89.     process: UNTRACED POINTER TO LONGINT;
  90.   END;
  91.  
  92.  
  93. VAR
  94.  
  95.   rda: Dos.RDArgsPtr;
  96.   args: ArgsStruct;
  97.   process: Dos.ProcessPtr;
  98.   buffer: ARRAY 256 OF CHAR;
  99.   success: BOOLEAN;
  100.  
  101.  
  102. (* Convert a BSTR to a normal string *)
  103.  
  104. PROCEDURE BstrToString(from: Dos.BSTR;
  105.                      VAR to: ARRAY OF CHAR;
  106.                 VAR success: BOOLEAN);
  107.  
  108. VAR
  109.  
  110.   i, len: INTEGER;
  111.  
  112. BEGIN
  113.  
  114.   success := FALSE;
  115.   len := ORD(from[0]);
  116.   IF LEN(to) > len THEN
  117.     FOR i := 1 TO len DO
  118.       to[i-1] := from[i];
  119.     END;
  120.     to[len] := 0X;
  121.     success := TRUE;
  122.   END;
  123.  
  124. END BstrToString;
  125.  
  126.  
  127. (************************************************************************)
  128.  
  129. BEGIN
  130.  
  131.   rda := Dos.ReadArgs(template, args, NIL);
  132.   Exec.Forbid;
  133.   process := Dos.FindCliProc(args.process^);
  134.  
  135.   IF process=NIL THEN
  136.     Exec.Permit;
  137.     Dos.PrintF(noSuchProcess);
  138.     HALT(10);
  139.   END;
  140.  
  141.   BstrToString(process.cli.setName, buffer, success);
  142.   Exec.Permit;
  143.   IF ~success THEN
  144.     HALT(10);
  145.   END;
  146.   Dos.PrintF(buffer); Dos.PrintF("\n");
  147.  
  148. CLOSE
  149.  
  150.   Dos.FreeArgs(rda);
  151.  
  152. END StealCD.
  153.